package com.qimo.zzy.service;

import com.qimo.zzy.dao.CollectionDao;
import com.qimo.zzy.entity.ResultEntity;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class CollectionService {
    @Resource
    CollectionDao collectionDao;

    private static final Logger logger = LoggerFactory.getLogger(UserService.class);//日志。getLogger需要传入当前的类名

    /**
     * 查询当前用户的所有收藏
     *
     * @param uid
     * @return
     */
    public String getAllCollection(int uid) {
        try {
            return ResultEntity.success(collectionDao.getAllCollection(uid));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 删除这条收藏
     *
     * @param pid
     * @return
     */
    public String deleteCollection(int uid,int pid) {
        try {
            return ResultEntity.success(collectionDao.deleteCollection(uid,pid));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    /**
     * 将此商品加入收藏
     *
     * @param uid
     * @param pid
     * @return
     */
    public String creatCollection(int uid, int pid) {
        try {
            return ResultEntity.success(collectionDao.creatCollection(uid, pid));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }
}
